﻿using CloudFranceTriple.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace CloudFranceTriple.Tests.Areas.Forum
{
    [TestClass]
    public class PollAnswerControllerTest : UnitTestBase
    {
        private Int32 _pollId = 333;
        private Int32 _pollAnswerId = 912;

        private DateTime _now = DateTime.UtcNow;

        [TestMethod]
        [TestCategory("Polling")]
        public void PollAnswerController_Create_Post_ModelIsValid()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.PollAnswerController(GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            var PollAnswerset = new PollAnswerSet
            {
                LabelPollAnwser = "Answer - Unit Test",
                NumberVotePollAnswer = 0,
                Poll_Id = _pollId
            };

            // Act
            var result = controller.Create(PollAnswerset) as RedirectToRouteResult;
            UnitTestPollAnswerId = PollAnswerset.Id;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Polling")]
        public void PollController_Poll()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.PollController(GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Poll(_pollAnswerId) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Polling")]
        public void PollAnswerController_Create_Get()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.PollAnswerController(GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Create(_pollId) as PartialViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Polling")]
        public void PollAnswerController_Index()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.PollAnswerController(GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Index(_pollId) as PartialViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Polling")]
        public void PollAnswerController__Edit_Get()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.PollAnswerController(GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Edit(_pollAnswerId) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Polling")]
        public void PollAnswerController__Edit_Post()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.PollAnswerController(GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            var PollAnswerset = new PollAnswerSet
            {
                Id = _pollAnswerId,
                LabelPollAnwser = "Answer - Unit Test",
                NumberVotePollAnswer = 0,
                Poll_Id = _pollId
            };

            // Act
            var result = controller.Edit(PollAnswerset) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Polling")]
        public void PollAnswerController_Delete_Get()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.PollAnswerController(GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Delete(_pollAnswerId) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Polling")]
        public void PollAnswerController_ShowWhoPolledWhat()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.PollAnswerController(GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.ShowWhoPolledWhat(_pollAnswerId) as PartialViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Polling")]
        public void PollAnswerController_DeleteConfirmed_Post()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.PollAnswerController(GetWebSecurity.Object);

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.DeleteConfirmed(UnitTestPollAnswerId) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
        }
    }
}